import * as echarts from "echarts";

const font_size =  16
/**
 * @description: 生成ec图表配置信息
 * @author: 王琛
 * @Date: 2022-11-25 15:29:43
 * @param {*}
 * @return {*}
 */
export function getOptions({xAxis = {}, series = []} = {}) {
	let options = {
		tooltip: {
			trigger: "axis",
			axisPointer: {
				type: "line",
				label: {
					backgroundColor: "#FFF",
				},
			},
			textStyle:{
				fontSize:font_size
			}
		},
		// dataZoom: {
		// 	type: "inside",
		// 	maxValueSpan: 7,
		// 	minValueSpan: 7,
		// },
		legend: {
			itemWidth: 16, // 设置宽度
			itemHeight: 8, // 设置高度
			top: "0%",
			right: "0%",
			itemGap: 16,
			textStyle: {
				color: '#FFF',
				fontSize:font_size
			}
		},
		grid: {
			top: 30,
			left: "0%",
			right: "0%",
			bottom: 10,
			containLabel: true,
		},
		xAxis: [
			{
				type: "category",
				data: xAxis.data,
				axisLabel: {
					textStyle: {
						color: "#fff",
						fontSize:font_size
					},
					borderType: "dotted"
				},
				axisLine: {
					
					lineStyle: {
						color: "#fff"
					}
				},
				axisTick: {
					show: false,
				},
			},
		],
		yAxis: [
			{
				type: "value",
				axisLabel: {
					textStyle: {
						color: "#fff",
						fontSize:font_size
					},
				},
				splitLine: {
					lineStyle: {
						type: "dotted"
					},
				},
				axisLine: {
					lineStyle: {
						color: "#fff"
					}
					
				},
			},
		],
		series: series.map((series_item) => getEcSeries(series_item)),
	}
	return options;
}

/**
 * @description: 获取当前折线图的 series 对象
 * @author: 王琛
 * @Date: 2022-11-25 16:18:34
 * @param {*}
 * @return {*}
 */
export function getEcSeries({name = "--", type = "line", data = [], areaColor = "66, 133, 244", label = {}} = {}) {
	let _options = null;
	if (type == "line") {
		_options = {
			name: name,
			type: "line",
			smooth: true,
			lineStyle: {
				width: 2,
				color: `rgba(${areaColor},1)`
			},
			showSymbol: true,
			symbolSize: 6,
			symbol: "circle",
			areaStyle: {
				opacity: 1,
				color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
					{
						offset: 0,
						color: `rgba(${areaColor},.2)`,
					},
					{
						offset: 1,
						color: `rgba(${areaColor},.0)`,
					},
				]),
			},
			label: {
				show: label.hasOwnProperty("show") ? label.show : true,
				
			},
			itemStyle: {
				color: `rgba(${areaColor}.1)`,
			},
			emphasis: {
				focus: "series",
			},
			data
		}
	} else {
		
		_options = {
			data: data,
			name: name,
			barWidth: 15,
			type: 'bar',
			itemStyle: {
				color: `rgba(${areaColor},1)`
			},
		}
	}
	return _options;
}


